package com.example.spring_native_es.datetime;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Set;

/**
 *
 */
public class DateTime {

    public static void localDate() {
        LocalDate now = LocalDate.now();
        System.out.println(now);
    }

    public static void localTime() {
        LocalTime now = LocalTime.now();
        System.out.println(now);

        LocalTime of = LocalTime.of(13, 59, 59, 999999999);
        LocalTime localTime = of.plusNanos(1);

        System.out.println(of);
        System.out.println(localTime.format(DateTimeFormatter.ISO_TIME));
    }

    public static void localDateTime() {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
    }


    public static void zonedDateTime() {

        ZonedDateTime now = ZonedDateTime.now();

        String format = now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        System.out.println(now);
        System.out.println(format);

        ZonedDateTime dateTimeInShanghai = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
        ZonedDateTime dateTimeInNewYork = dateTimeInShanghai.withZoneSameInstant(ZoneId.of("America/New_York"));

        System.out.println("DateTime in Shanghai: " + dateTimeInShanghai);
        System.out.println("DateTime in New York: " + dateTimeInNewYork);
    }


    public static void instant() {
        Instant now = Instant.now();
        System.out.println(now.getNano());
        System.out.println(now);
    }

    public static void main(String[] args) {
        Set<String> allZoneIds = ZoneId.getAvailableZoneIds();

        for (String zoneId : allZoneIds) {
            System.out.println(zoneId);
        }
        localDate();
        localTime();

        localDateTime();
        zonedDateTime();

        instant();
    }
}
